import { Module } from '@nestjs/common';
import { UploadService } from './upload.service';
import { UploadController } from './upload.controller';
import { MulterModule } from '@nestjs/platform-express';
import path from 'node:path';
import { diskStorage } from 'multer';

@Module({
  controllers: [UploadController],
  providers: [UploadService],
  imports: [
    MulterModule.register({
      storage: diskStorage({
        // 不要使用path.join nest 打包获取的是 dist 目录
        // destination: path.join(__dirname, '../../uploads'),
        destination: `${process.cwd()}\\src\\uploads`,
        filename: (_, file, callback) => {
          const fileName = `${new Date().getTime()}${path.extname(file.originalname)}`;
          return callback(null, fileName);
        },
      }),
    }),
  ],
})
export class UploadModule {}
